from PIL import Image, ImageFile
from io import BytesIO
import base64


def img2base64(image_file: ImageFile):
    """
    Convert a PIL Image to a base64 encoded string.

    Args:
        Image (PIL.Image): The image to convert.

    Returns:
        str: Base64 encoded string of the image.
    """
    buffered = BytesIO()
    image_file.save(buffered, format=image_file.format)
    img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
    return img_str
